

<!DOCTYPE html>
<html lang="en" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/my_blog/img/favicon.ico">
  <link rel="icon" type="image/png" href="/my_blog/img/favicon.ico">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  <title>JavaScript字符串面试题 - Defame。</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/my_blog/lib/hint/hint.min.css" />

  
    
    <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/github-gist.min.css" />
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_6peoq002giu.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_pjno9b9zyxs.css">


<link  rel="stylesheet" href="/my_blog/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/my_blog/js/utils.js" ></script>
  <script  src="/my_blog/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 4.2.1"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/my_blog/">&nbsp;<strong>Defame。</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my_blog/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my_blog/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my_blog/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my_blog/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my_blog/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" href="javascript:">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner intro-2" id="background" parallax=true
         style="background: url('/my_blog/img/jq.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container page-header text-center fade-in-up">
            <span class="h2" id="subtitle">
              
            </span>

            
              
  <div class="mt-3 post-meta">
    <i class="iconfont icon-date-fill" aria-hidden="true"></i>
    <time datetime="2020-05-25 15:45" pubdate>
      May 25, 2020 pm
    </time>
  </div>


<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      946 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      11
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto" id="post">
            <!-- SEO header -->
            <h1 style="display: none">JavaScript字符串面试题</h1>
            
            <div class="markdown-body" id="post-body">
              <h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><h4 id="12道JavaScript面试题"><a href="#12道JavaScript面试题" class="headerlink" title="12道JavaScript面试题"></a>12道JavaScript面试题</h4><h3 id="1、如何判断一个字符串中是否包含某一个字符？"><a href="#1、如何判断一个字符串中是否包含某一个字符？" class="headerlink" title="1、如何判断一个字符串中是否包含某一个字符？"></a>1、如何判断一个字符串中是否包含某一个字符？</h3><pre><code class="hljs gml">方法一、indexOf，返回值是字符在字符串中的位置(数字)，如果在第一个位置返回<span class="hljs-number">0</span>，没有就返回<span class="hljs-number">-1</span>
方法二、includes(es6)，返回值是布尔类型
方法三、正则表达式，比如:判断是否有<span class="hljs-symbol">x</span>：<span class="hljs-string">'abc'</span>.match(/<span class="hljs-symbol">x</span>/)</code></pre>
<h3 id="2、如何截取字符串中第3-5个字符？"><a href="#2、如何截取字符串中第3-5个字符？" class="headerlink" title="2、如何截取字符串中第3~5个字符？"></a>2、如何截取字符串中第3~5个字符？</h3><pre><code class="hljs mel">比如：<span class="hljs-string">'ssffdwwqwqda'</span>截取<span class="hljs-number">3</span><span class="hljs-number">-5</span>的结果是<span class="hljs-string">"ffd"</span>
方法一、<span class="hljs-keyword">substring</span>,<span class="hljs-string">'ssffdwwqwqda'</span>.<span class="hljs-keyword">substring</span>(<span class="hljs-number">2</span>,<span class="hljs-number">5</span>)
方法二、substr，<span class="hljs-string">'ssffdwwqwqda'</span>.substr(<span class="hljs-number">2</span>,<span class="hljs-number">3</span>)
区别在于:第二个参数的含义不同，第一个是结束的下标(<span class="hljs-keyword">substring</span>)，第二个是截取的长度(substr)</code></pre>
<h3 id="3、如何获取一个字符串的长度？"><a href="#3、如何获取一个字符串的长度？" class="headerlink" title="3、如何获取一个字符串的长度？"></a>3、如何获取一个字符串的长度？</h3><pre><code class="hljs livecodeserver"><span class="hljs-built_in">length</span>属性。比如:<span class="hljs-string">'sjitutu'</span>.<span class="hljs-built_in">length</span></code></pre>
<h3 id="4、如何把字符串中的字母转成大写？转成小写呢？"><a href="#4、如何把字符串中的字母转成大写？转成小写呢？" class="headerlink" title="4、如何把字符串中的字母转成大写？转成小写呢？"></a>4、如何把字符串中的字母转成大写？转成小写呢？</h3><pre><code class="hljs gcode">toUpperCase:转大写。<span class="hljs-string">'abc'</span>.toUpperCase<span class="hljs-comment">()</span>
toLowerCase:转小写<span class="hljs-string">'。BCA'</span>.toLowerCase<span class="hljs-comment">()</span></code></pre>
<h3 id="5、JS-中如何将单词的首字母大写？"><a href="#5、JS-中如何将单词的首字母大写？" class="headerlink" title="5、JS 中如何将单词的首字母大写？"></a>5、JS 中如何将单词的首字母大写？</h3><h4 id="答：JS中没有自带首字母转大写的功能，我们可以自己实现一个："><a href="#答：JS中没有自带首字母转大写的功能，我们可以自己实现一个：" class="headerlink" title="答：JS中没有自带首字母转大写的功能，我们可以自己实现一个："></a>答：JS中没有自带首字母转大写的功能，我们可以自己实现一个：</h4><pre><code class="hljs qml"><span class="hljs-number">1.</span>为字符串原型添加一个方法，在<span class="hljs-built_in">string</span>原型上添加(<span class="hljs-built_in">String</span>.prototype)的函数，可以在所有的字符串上直接使用

<span class="hljs-built_in">String</span>.prototype.firstUpperCase = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>&#123;
    <span class="hljs-comment">// 通过正则表达式，匹配第一个字符，和后面的字符</span>
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.replace(<span class="hljs-regexp">/\b(\w)(\w*)/g</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">$0, $1, $2</span>) </span>&#123;
        <span class="hljs-comment">// 将第一个字符转大写 +  后面的字符转小转</span>
        <span class="hljs-keyword">return</span> $<span class="hljs-number">1.</span>toUpperCase() + $<span class="hljs-number">2.</span>toLowerCase();
    &#125;);
&#125;

<span class="hljs-number">2.</span>添加完之后，所以的字符串就可以直接使用 firstUpperCase 方法了

<span class="hljs-string">'abcdefg'</span>.firstUpperCase()</code></pre>
<h3 id="6、如何把字符串中所有的数字转成"><a href="#6、如何把字符串中所有的数字转成" class="headerlink" title="6、如何把字符串中所有的数字转成 * ?"></a>6、如何把字符串中所有的数字转成 * ?</h3><pre><code class="hljs arcade">答：比如：<span class="hljs-string">'ab32abd4r43af'</span> ==&gt; <span class="hljs-string">'ababd*raf'</span>
实现思路：使用正则表达式+replace方法
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">replaceXX</span>(<span class="hljs-params">str</span>) </span>&#123;
    <span class="hljs-comment">// 替换：第一个参数：正则表达式</span>
    <span class="hljs-comment">// \\d：数字</span>
    <span class="hljs-comment">// /g：全局替换，如果不加只会替换第一个数字</span>
    <span class="hljs-keyword">return</span> str.replace(<span class="hljs-regexp">/\d/g</span>, <span class="hljs-string">'*'</span>)
&#125;</code></pre>
<h3 id="7、如何将字符串转成数组？"><a href="#7、如何将字符串转成数组？" class="headerlink" title="7、如何将字符串转成数组？"></a>7、如何将字符串转成数组？</h3><pre><code class="hljs coq">使用<span class="hljs-built_in">split</span></code></pre>
<h3 id="8、如何将数组转成字符串？"><a href="#8、如何将数组转成字符串？" class="headerlink" title="8、如何将数组转成字符串？"></a>8、如何将数组转成字符串？</h3><pre><code class="hljs sqf">方法一：<span class="hljs-built_in">join</span>，优点：可以任意指定分隔符
比如： [<span class="hljs-string">'abc'</span>,<span class="hljs-string">'bcd'</span>,<span class="hljs-string">'des'</span>,<span class="hljs-string">'cda'</span>].<span class="hljs-built_in">join</span>(<span class="hljs-string">'-'</span>)  ===&gt;  <span class="hljs-string">'abc-bcd-des-cda'</span>
方法二：<span class="hljs-built_in">toString</span>，默认是以 ，分隔</code></pre>
<h3 id="9、如何合并两个字符串？"><a href="#9、如何合并两个字符串？" class="headerlink" title="9、如何合并两个字符串？"></a>9、如何合并两个字符串？</h3><pre><code class="hljs coffeescript">方法一：使用+号：<span class="hljs-string">'abc'</span>+<span class="hljs-string">'bcd'</span> =<span class="hljs-function">=&gt;</span> abcbcd
方法二：使用concat：<span class="hljs-string">'abc'</span>.concat(<span class="hljs-string">'bcd'</span>) =<span class="hljs-function">=&gt;</span> abcbcd</code></pre>
<h3 id="10、请说出至少-10-个操作字符串的方法？"><a href="#10、请说出至少-10-个操作字符串的方法？" class="headerlink" title="10、请说出至少 10 个操作字符串的方法？"></a>10、请说出至少 10 个操作字符串的方法？</h3><pre><code class="hljs maxima"><span class="hljs-built_in">split</span>：转数组
<span class="hljs-built_in">join</span>：转字符串
toString：转字符串
<span class="hljs-built_in">concat</span>：连接
<span class="hljs-built_in">substring</span>：从开始到结束下标截取
substr：从开始截取一定长度的字符串
indexOf：查看一个字符串中某一个子字符串的位置
replace：字符串替换，替换时也可以使用正则来匹配
match：用字符串去匹配一个正则
toUpperCase：转大写
toLowerCase：转小写</code></pre>
<h3 id="11、如何把一个字符串中所有的手机号码中的中间4位数字变成-？"><a href="#11、如何把一个字符串中所有的手机号码中的中间4位数字变成-？" class="headerlink" title="11、如何把一个字符串中所有的手机号码中的中间4位数字变成 ****？"></a>11、如何把一个字符串中所有的手机号码中的中间4位数字变成 ****？</h3><pre><code class="hljs javascript">比如：<span class="hljs-string">'ab13455334444sd'</span> ==&gt; <span class="hljs-string">'ab134****4444d'</span>
使用正则表达式+replace方法
<span class="hljs-function"><span class="hljs-keyword">function</span>  <span class="hljs-title">replaceXX</span>(<span class="hljs-params">str</span>) </span>&#123;
   <span class="hljs-comment">// 替换：第一个参数：正则表达式</span>
   <span class="hljs-comment">// $1：正则中第 1 个括号中的内容（反向引用）</span>
   <span class="hljs-comment">// $2：正则中第 2 个括号中的内容（反向引用）</span>
   <span class="hljs-comment">// $3：正则中第 3 个括号中的内容（反向引用）</span>
   <span class="hljs-keyword">return</span>  str.replace(<span class="hljs-regexp">/(1\d&#123;2&#125;)(\d&#123;4&#125;)(\d&#123;4&#125;)/g</span>, <span class="hljs-string">'$1****$3'</span>)
&#125;
<span class="hljs-keyword">let</span>  a  =  <span class="hljs-string">'abdf13344445555das'</span>
<span class="hljs-built_in">console</span>.log(replaceXX(a))</code></pre>
<h3 id="12、转成驼峰命名法？"><a href="#12、转成驼峰命名法？" class="headerlink" title="12、转成驼峰命名法？"></a>12、转成驼峰命名法？</h3><pre><code class="hljs javascript">比如：<span class="hljs-string">"get-element-by-id"</span> ==》 getElementById
思路：先转数组，循环数组处理每个单词首字母大写，转回字符串。
<span class="hljs-built_in">String</span>.prototype.firstUpperCase = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>&#123;
    <span class="hljs-comment">// 通过正则表达式，匹配第一个字符，和后面的字符</span>
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.replace(<span class="hljs-regexp">/\b(\w)(\w*)/g</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">$<span class="hljs-number">0</span>, $<span class="hljs-number">1</span>, $<span class="hljs-number">2</span></span>) </span>&#123;
        <span class="hljs-comment">// 将第一个字符转大写 +  后面的字符转小转</span>
        <span class="hljs-keyword">return</span> $<span class="hljs-number">1.</span>toUpperCase() + $<span class="hljs-number">2.</span>toLowerCase();
    &#125;);
&#125;
<span class="hljs-keyword">let</span> str = <span class="hljs-string">"get-element-by-id"</span>
str = str.split(<span class="hljs-string">"-"</span>).map(<span class="hljs-function">(<span class="hljs-params">v,k</span>)=&gt;</span>&#123;
    <span class="hljs-keyword">if</span>(k&gt;<span class="hljs-number">0</span>) &#123;
       <span class="hljs-keyword">return</span> v.firstUpperCase()
    &#125; <span class="hljs-keyword">else</span> &#123;
        <span class="hljs-keyword">return</span> v
    &#125;
&#125;).join()</code></pre>
            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/my_blog/categories/%E5%89%8D%E7%AB%AF%E9%9D%A2%E8%AF%95/">前端面试</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/my_blog/tags/JavaScript%E9%9D%A2%E8%AF%95%E9%A2%98/">JavaScript面试题</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" target="_blank" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！</p>
              
              
                <div class="post-prevnext row">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/my_blog/2020/05/26/JavaScript-ajax/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">JavaScript-ajax</span>
                        <span class="visible-mobile">Previous</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/my_blog/2020/05/23/%E5%85%B3%E4%BA%8Ecss%E4%B8%ADbackgroundimage%E7%9A%84%E6%8A%80%E5%B7%A7/">
                        <span class="hidden-mobile">关于css中backgroundimage的技巧</span>
                        <span class="visible-mobile">Next</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
              <!-- Comments -->
              <article class="comments" id="comments">
                
                
  <div class="disqus" style="width:100%">
    <div id="disqus_thread"></div>
    <script type="text/javascript">
      function loadDisqus() {
        var disqus_config = function () {
          this.page.url = 'https://defame.gitee.io/my_blog/2020/05/25/JavaScript字符串面试题/';
          this.page.identifier = '/2020/05/25/JavaScript字符串面试题/';
        };
        (function () {
          var d = document,
            s = d.createElement('script');
          s.src = '//' + '' + '.disqus.com/embed.js';
          s.setAttribute('data-timestamp', new Date());
          (d.head || d.body).appendChild(s);
        })();
      }
      waitElementVisible('disqus_thread', loadDisqus);
    </script>
    <noscript>Please enable JavaScript to view the
      <a href="https://disqus.com/?ref_noscript" target="_blank" rel="nofollow noopener noopener">comments powered by Disqus.</a>
    </noscript>
  </div>


              </article>
            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;TOC</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">Search</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">keyword</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
    <div>
      <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a>
      <i class="iconfont icon-love"></i>
      <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener">
        <span>Fluid</span></a>
    </div>
    
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


    
  <!-- 备案信息 -->
  <div class="beian">
    <a href="http://beian.miit.gov.cn/" target="_blank"
       rel="nofollow noopener">京ICP证123456号</a>
    
      <a
        href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=12345678"
        rel="nofollow noopener"
        class="beian-police"
        target="_blank"
      >
        <span class="beian-police-sep">&nbsp;|&nbsp;</span>
        
          <img src="/my_blog/img/police_beian.png" srcset="/my_blog/img/loading.gif" alt="police-icon" />
        
        <span>京公网安备12345678号</span>
      </a>
     
  </div>


    
  </div>
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/my_blog/js/debouncer.js" ></script>
<script  src="/my_blog/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/my_blog/js/lazyload.js" ></script>
  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/my_blog/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: '#post-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "JavaScript字符串面试题&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/my_blog/js/local-search.js" ></script>
  <script>
    var path = "/my_blog/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>







  
  
    <script>
      !function (e, t, a) {
        function r() {
          for (var e = 0; e < s.length; e++) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[e].y--, s[e].scale += .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:" + s[e].x + "px;top:" + s[e].y + "px;opacity:" + s[e].alpha + ";transform:scale(" + s[e].scale + "," + s[e].scale + ") rotate(45deg);background:" + s[e].color + ";z-index:99999");
          requestAnimationFrame(r)
        }

        function n() {
          var t = "function" == typeof e.onclick && e.onclick;
          e.onclick = function (e) {
            t && t(), o(e)
          }
        }

        function o(e) {
          var a = t.createElement("div");
          a.className = "heart", s.push({
            el: a,
            x: e.clientX - 5,
            y: e.clientY - 5,
            scale: 1,
            alpha: 1,
            color: c()
          }), t.body.appendChild(a)
        }

        function i(e) {
          var a = t.createElement("style");
          a.type = "text/css";
          try {
            a.appendChild(t.createTextNode(e))
          } catch (t) {
            a.styleSheet.cssText = e
          }
          t.getElementsByTagName("head")[0].appendChild(a)
        }

        function c() {
          return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"
        }

        var s = [];
        e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) {
          setTimeout(e, 1e3 / 60)
        }, i(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"), n(), r()
      }(window, document);
    </script>
  














<script src="/my_blog/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
